﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;

namespace Inspired.Euler
{
    public static class Problem034
    {
        static void Main()
        {
            //Enumerable.Range(3, 9999999)

            int sum = 0;
            for(int i = 3; i < 999999 ; i++)
            {
                if (i == i.ToString().ToCharArray().Aggregate(new BigInteger(),
                    (seed, c) => seed = BigInteger.Add(seed, ((int)Char.GetNumericValue(c)).Factorial())))
                {
                    sum += i;
                }
            }
            sum.DisplayAndPause();
        }
    }
}
